package service;

import dao.ImplementManager;
import jakarta.servlet.ServletException;
import jakarta.servlet.annotation.WebServlet;
import jakarta.servlet.http.HttpServlet;
import jakarta.servlet.http.HttpServletRequest;
import jakarta.servlet.http.HttpServletResponse;
import jakarta.servlet.http.HttpSession;

import java.io.IOException;
@WebServlet("/area_loginServlet")
public class Area_LoginServlet extends HttpServlet {
    @Override
    protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        resp.setContentType("text/html;charset=utf-8");
        String managername = req.getParameter("managername");
        String managerpassword = req.getParameter("managerpassword");
        String type = req.getParameter("type");
        ImplementManager implementManager = new ImplementManager();
        boolean login=implementManager.managerLogin(type, managername, managerpassword);
        if (!login) {
            req.setAttribute("login_fail","用户名或密码错误");
            req.getRequestDispatcher("/area_login.jsp").forward(req,resp);
        }
        else {
          HttpSession session=req.getSession();
          session.setAttribute("type",type);
            req.getRequestDispatcher("/areanote.jsp").forward(req,resp);
        }

    }



    @Override
    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        this.doPost(req, resp);
    }

}
